home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / DOSPAWN.C < prev    next >
C/C++ Source or Header  |  1990-11-24  |  2KB  |  98 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "headedit.h"
  4.  
  5. /* Performs all external calls; preserves screen, swaps if ok */
  6.  
  7. extern void pascal _REINITOVERLAYS (void);  /* Reinit overlay int vector */
  8.  
  9.  
  10. void pascal do_spawn (char *dostring) {
  11.  
  12.      int  drive;
  13.      char dir[MAXDIR];
  14.      char middle[82];
  15.      char *pp;
  16.      char *screenbuf;
  17.      int *p;
  18.      int oldx,oldy,x,y;
  19.  
  20.      screenbuf=(char *)malloc((maxx * maxy) * 2);
  21.      if(!screenbuf) {
  22.         error_message(" Not enough memory ");
  23.         pause();
  24.         return;
  25.      }
  26.      curr_cursor(&oldx,&oldy);
  27.      p=(int *)screenbuf;
  28.      for(y=0;y<maxy;y++)
  29.         for(x=0;x<maxx;x++)
  30.            *p++=vpeek(VSG,vad(x,y));
  31.      if(!*dostring || !dostring) {
  32.         fputs("\x1b[2J\x1b[0m`EXIT' to return...'\n",stdout);
  33.      }
  34.      drive=getdisk();
  35.      getcurdir(++drive,dir);
  36.      pp=dostring;
  37.      if(!*dostring || !dostring) {
  38.         pp=getenv("COMSPEC");
  39.         if (!pp) pp="COMMAND.COM";
  40.      }
  41.      spawnit(pp);
  42.      setdisk (--drive);
  43.      strcpy(middle,"\\");
  44.      strcat(middle,dir);
  45.      chdir(middle);
  46.      cursor(oldx,oldy);
  47.      p=(int *)screenbuf;
  48.      for(y=0;y<maxy;y++)
  49.         for(x=0;x<maxx;x++)
  50.            vpoke(VSG,vad(x,y),*p++);
  51.      free(screenbuf);
  52. }
  53.  
  54.  
  55.  
  56. char pascal spawnit (char *strr) {
  57.  
  58.    char *e[26];
  59.    static char a[256];
  60.    char *p;
  61.    char *pp;
  62.    register word x;
  63.    int level=0;
  64.    union REGS r;
  65.  
  66.    if(!*strr || strr==NULL) return (level=1);
  67.    strcpy(a,strr);
  68.    if (swap) {
  69.         p=strtok(a," ");
  70.         if (!p) return 99;
  71.         if (!strchr(p,':') && !strchr(p,'\\')) p=searchpath(a);
  72.         if (!p) return 99;
  73.         pp=strtok(0,"\n");
  74.         if (!pp) pp="";
  75.         level=doswap(p,pp);
  76.         if (level!=(-1)) goto Getlevel;
  77.    }
  78.    for (x=0;x<26;x++) e[x]=NULL;
  79.    e[0]=strtok(a," ");
  80.    for (x=1;(e[x]=strtok(0," "));x++) if (x==25) break;
  81.    level=(int)spawnvp(P_WAIT,a,e);
  82. Getlevel:
  83.    if (!level) {
  84.        r.h.ah=77;
  85.        int86(33,&r,&r);
  86.        level=(int)r.h.al;
  87.    }
  88.    _REINITOVERLAYS();
  89.    _AX=0;  /* ReInitialize mouse */
  90.    geninterrupt(0x33);
  91.    if(usemouse) {    /* Make sure mouse cursor stays hidden */
  92.       _AX=2;
  93.       geninterrupt(0x33);
  94.    }
  95.    return (char)level;
  96. }
  97.  
  98.